package letcode.problem.dynamicProgra;

/**
 * 最长递增子序列
 * https://leetcode.cn/problems/longest-increasing-subsequence/description/?envType=study-plan-v2&envId=dynamic-programming
 * */
public class LongestIncreasingSubsequence {

    /**
     * f(x) = f(x-1)+ isIncreasing(gx)
     *
     * @param nums 遍历的数组
     * @return 最长递增子序列
     * */
    public static int lengthOfLIS(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int maxans = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            maxans = Math.max(maxans, dp[i]);
        }

        return maxans;
    }

    public static void main(String[] args) {
        System.out.println(
                lengthOfLIS(new int[]{
                        0,1,0,3,2,3
                })
        );
    }
}
